﻿@model DataModel
@{
    Layout = null;
}
@using NotepadDemo.Models
<!DOCTYPE html>
<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title>Index</title>
    <link href="~/Css/StyleSheet1.css" rel="stylesheet" />
</head>
<body>
<div id="head">
    <textarea id="content">@ViewBag.content</textarea>
    <input id="lock" type="hidden" value="@ViewData["IsLocked"]"/>
    <input id="uri" type="hidden" value="@ViewData["Uri"]"/>
    <input id="pwd" type="hidden" value="@ViewData["Password"]"/>   
</div>
    <div id="tial" style="text-align:center; margin:0 auto;">
        <button id="hrefs" style="background: none; border: none; color: #9ba7c0;"></button>
        <button id="save">Save</button>
        <button id="setPassword">Set Password</button>
    </div>
    <script src="~/Scripts/jquery-1.9.0.js"></script>
    <script src="~/Scripts/bootstrap.js"></script>
    <script type="text/javascript">
        $(function () {

            $('#hrefs').text(location.href);

            IsEditTextArea();

            $('#setPassword').click(function () { 
                var pwd = prompt('Please type password', '');
                if (pwd != '' && pwd != null) {
                    $.ajax({

                        url: '/Notepad/SetPassword',
                        type: 'POST',
                        data: { pwd: pwd, content: $('#content').val(), uri: $('#uri').val(), lock: $('#lock').val() },
                        success: function (data) {
                            if (data == 'ok') {
                            }
                        },
                        error: function (a, o, e) {
                            alert('错误信息' + e.toString());
                        }
                    });

                }
            });

            $('#save').click(function () {
                $.ajax({

                    url: '/Notepad/Save',
                    type: 'POST',
                    data: { pwd: $('#pwd').val(), content: $('#content').val(), uri: $('#uri').val(), lock: $('#lock').val() },
                    success: function (data) {
                        if (data == 'ok') {
                            alert('保存成功');

                        }

                    },
                    error: function (a, o, e) {
                        alert('错误信息' + e.toString());
                    }
                });

            });




        })

        function IsEditTextArea() {
            var islock = $('#lock').val();

            if (islock == 'True')
                $('#content').attr('readonly', true);


        }
    </script>
</body>
</html>
